package jqgridjavawrapper;

/**
 * @author Isuru Madushanka Weerarathna
 * @contact uisurumadushanka89@gmail.com
 */
public class JQGridSubGridModel implements JQPropertyMaker {

    private String[] names = null;
    private String[] width = null;
    private JQGridAlignments[] aligns = null;
    private String[] params = null;
    private String[] mappings = null;

    public StringBuilder generateProperties() {
        StringBuilder sb = new StringBuilder();

        if (names != null) {
            sb.append("\nname: [");
            for (int i=0;i<names.length;i++) {
                if (i>0) sb.append(',');
                sb.append(names[i]);
            }
            sb.append("],");
        }
        if (width != null) {
            sb.append("\nwidth: [");
            for (int i=0;i<width.length;i++) {
                if (i>0) sb.append(',');
                sb.append(width[i]);
            }
            sb.append("],");
        }
        if (aligns != null) {
            sb.append("\nalign: [");
            for (int i=0;i<aligns.length;i++) {
                if (i>0) sb.append(',');
                sb.append(aligns[i].toString());
            }
            sb.append("],");
        }
        if (params != null) {
            sb.append("\nparams: [");
            for (int i=0;i<params.length;i++) {
                if (i>0) sb.append(',');
                sb.append(params[i]);
            }
            sb.append("],");
        }
        if (mappings != null) {
            sb.append("\nmapping: [");
            for (int i=0;i<mappings.length;i++) {
                if (i>0) sb.append(',');
                sb.append(mappings[i]);
            }
            sb.append("],");
        }

        if (sb.length()>0) {
            sb.deleteCharAt(sb.length()-1);
            sb.insert(0, "\nsubGridModel: {[");
            sb.append("}],");
        }

        return sb;
    }

}
